package com.ssm.service.impl;

import com.ssm.controller.Code;
import com.ssm.dao.BookDao;
import com.ssm.exception.BusinessException;
import com.ssm.exception.SystemException;
import com.ssm.pojo.Book;
import com.ssm.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public boolean insert(Book book) {
        return bookDao.insert(book) > 0;
    }

    @Override
    public boolean update(Book book) {
        return bookDao.update(book) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return bookDao.delete(id) > 0;
    }

    @Override
    public Book selectBookById(Integer id) {
        /*if (id == 1){
            throw new BusinessException(Code.BUSINESS_ERR,"别乱输数据");
        }*/

        return bookDao.selectBookById(id);
    }

    @Override
    public List<Book> selectAll() {
        /*try {
            int i = 1/0;
        }catch (Exception e){
            throw new SystemException(Code.SYSTEM_ERR,"服务器异常",e);
        }*/

        return bookDao.selectAll();
    }
}
